
local MyApp = class("MyApp", cc.load("mvc").AppBase)

function MyApp:onCreate()
    math.randomseed(os.time())
end

function MyApp:onEnterBackground()
    if not self.is_background then
        self.is_background=true
        if NetEngine then
            NetEngine:onEnterBackground()
        end
        if FzEventCenter and FzEvent then 
            FzEventCenter:DispichEvent(FzEvent.EnterBackground)
        end
    end
end

function MyApp:onBackToForeground()
    if self.is_background then
        self.is_background=false
        if NetEngine then
            NetEngine:onBackToForeground()
        end
        if FzEventCenter and FzEvent then 
            FzEventCenter:DispichEvent(FzEvent.BackToForeground)
        end
    end
end

--print err msg
function MyApp.printErrOnScreen(err)
	if DEBUG_MODE or cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then
		local self = MyApp
		if self.errlabel then return end
		
		self.errlabel = cc.Label:createWithSystemFont(err, "arial", 22)
		self.errlabel:setDimensions(display.width, display.height)
		self.errlabel:setPosition(display.cx, 0)
		self.errlabel:setColor(cc.c4b(232, 53, 15, 255))
		local scene = cc.Director:getInstance():getRunningScene()
		if scene then
			scene:addChild(self.errlabel,Zorder.ERROR_TEXT)
		end
	end
end

function MyApp:restart()
    if cc.exports.fix_restart_lua then --C++已经加了重启lua方法，
        print("has func restart")
        fix_restart_lua()
    else
--        FZutil.clearCache()
--        if NetEngine then NetEngine:reset() end
--        if ModelsManager then ModelsManager:clean() end     --清理以前的事件
        --if DyDataManager then DyDataManager:reset() end     --清理数据，防止切换账号数据错误
        --if GlobalSchedulerHelper then GlobalSchedulerHelper.clearAllHandler() end
        --if SDKCenter then SDKCenter:dataReset() end
        self:enterScene("LoginScene")
    end
end

return MyApp
